package com.bw.video_module.video;

import com.bw.common.entity.LiveDataEntity;
import com.bw.common.mvvm.viewmodel.BaseViewModel;
import com.bw.network_sdk.entity.BaseEntity;
import com.bw.network_sdk.videoentity.VideoEntity;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class VideoViewModel extends BaseViewModel<VideoModel> {

    @Override
    protected void initData() {
        mModel.requestVideo(0,"all",10,10)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(this);
    }

    @Override
    protected void onRestle(BaseEntity entity) {
        if (entity instanceof VideoEntity){
            VideoEntity videoEntity = (VideoEntity) entity;
            LiveDataEntity liveDataEntity = new LiveDataEntity();
            liveDataEntity.action = LiveDataEntity.LiveDataType.START_VIEW_MODEL;
            Map<LiveDataEntity.LiveDataType,Object> map = new HashMap<>();
            map.put(LiveDataEntity.LiveDataType.ENTITY,videoEntity);
            liveDataEntity.data = map;
            liveDataViewModel.post(liveDataEntity);
        }
    }
}
